package edu.wtbu.cs.androiddemo.activity.list;

import android.os.Bundle;
import android.widget.LinearLayout;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import edu.wtbu.cs.androiddemo.R;

public class RecyclerViewSampleActivity extends AppCompatActivity {

    private int[] icons = {R.drawable.a, R.drawable.b, R
            .drawable.c, R.drawable.d, R.drawable.e,
            R.drawable.f, R.drawable.g, R.drawable.h, R
            .drawable.i, R
            .drawable.j, R.drawable.k, R.drawable.l};
    private String[] titles = {"白鹃梅", "五色椒", "小檗",
            "李叶绣菊", "多花兰", "獐耳细辛", "铁茉莉", "三色狸藻", "东洋菊",
            "大花皇冠", "苹果花", "三弄芙蓉"};
    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_recycler_view_sample);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        recyclerView = findViewById(R.id.recyclerView);

     //   LinearLayoutManager linearLayoutManager = new LinearLayoutManager(RecyclerViewSampleActivity.this);

        //实现横向布局
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(RecyclerViewSampleActivity.this,
                LinearLayoutManager.HORIZONTAL,false);
        recyclerView.setLayoutManager(linearLayoutManager);

        //实现网格布局
//        GridLayoutManager gridLayoutManager = new GridLayoutManager(this,4,GridLayoutManager.VERTICAL,false);
//        recyclerView.setLayoutManager(gridLayoutManager);

        MyAdapter myAdapter = new MyAdapter(RecyclerViewSampleActivity.this);
        recyclerView.setAdapter(myAdapter);
    }
}